#!/usr/bin/env bash
source bashlib

unhandled=1
while getopts :vU opt; do
    case "$opt" in
        h) showHelp parseLogs 'Reformats verbose ubiquity log output to make it easier to understand.' 'Maarten Billemont' \
            -v 'Increase output verbosity.' \
            -U 'Hide warnings about unhandled ubiquity log output.' ;;
        v) (( ++_logVerbosity )) ;;
        U) unhandled=0 ;;
    esac
done

timePattern='[[:digit:]][[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]] [[:digit:]][[:digit:]]:[[:digit:]][[:digit:]]:[[:digit:]][[:digit:]][:.][[:digit:]][[:digit:]][[:digit:]]'

# Parse the log's lines into blocks of log statements (=logLines)
logLines=() logLine=
while read -r line; do
    line=${line%$'\r'} # DOS-to-UNIX

    [[ $line =~ ^$timePattern ]] && {
        [[ $logLine ]] && logLines+=("${logLine%$'\n'}") logLine=
    }
    logLine+=$line$'\n'

done

# Evaluate the log lines.
for logLine in "${logLines[@]}"; do
    trc "$logLine"

    time=0
    [[ $logLine =~ ^($timePattern) ]] && time=$(totime "${BASH_REMATCH[1]}")
    (( time == 0 || time - lastTime > 2000 )) && printf %s "$bold$black" && hr && printf %s "$reset"
    lastTime=$time

    if [[ $logLine != *'CoreData: Ubiquity:'* ]]; then
        [[ $logLine ]] || continue
        firstLogLine=${logLine%%$'\n'*} firstLogLine=${firstLogLine#*] }
        [[ ${logLine#*$firstLogLine} ]] && firstLogLine+=" [...]"
        [[ $firstLogLine = 'UbiquityStoreManager: '* ]] && app=${firstLogLine%%: *} firstLogLine=${firstLogLine#*: } || app='APP'
        inf -- "[$app] $firstLogLine"


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsExporter'*'exporting '@(inserted|updated|deleted)' objects:'* ]]; then
        # exporter localPeerID ubiquityRootLocation tempMoveTimer lastTransactionDate objects
        inserted=() updated=() deleted=() object=
        while read -r line; do
            if [[ $line = *'exporting inserted objects'* ]]; then
                mode=inserted
                trc 'mode %s' "$mode"
            elif [[ $line = *'exporting updated objects'* ]]; then
                mode=updated
                trc 'mode %s' "$mode"
            elif [[ $line = *'exporting deleted objects'* ]]; then
                mode=deleted
                trc 'mode %s' "$mode"
            elif [[ $line = '})'?(,) ]]; then
                object=${object% }
                eval "$(printf '%q+=(%q)' "$mode" "$object")"
                trc 'mode end %s: object=%s' "$mode" "$object"
            elif [[ $line =~ ^'<'.*/([^/]*/[^/]*)'> ; data: {' ]]; then
                object=${BASH_REMATCH[1]}": "
                trc 'object=<%s>' "$object"
            else
                line=${line//'"0x'+([[:alnum:]])' <x-coredata://'+([^\/])'/'/'"<'}
                object+="$line "
                trc 'object+=<%s>' "$line"
            fi
        done <<< "$logLine"

        inf '[iCloud] Exporting %d changes saved to store:' "$(( ${#inserted[@]} + ${#updated[@]} + ${#deleted[@]} ))"
        for object in "${inserted[@]}"; do
            logColor=$green inf "+ %s" "$object"
        done
        for object in "${updated[@]}"; do
            logColor=$blue inf "* %s" "$object"
        done
        for object in "${deleted[@]}"; do
            logColor=$red inf "- %s" "$object"
        done


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsExporter: '*'Successfully wrote transaction log:'* ]]; then
        # exporter localPeerID ubiquityRootLocation tempMoveTimer lastTransactionDate transactionLog transactionLogLocation transactionNumber
        log=? transaction=?
        while read -r line; do
            if [[ $line = 'transactionLogLocation: '* ]]; then
                log=${line##*/}
            elif [[ $line = 'transactionNumber: '* ]]; then
                transaction=${line##* }
            fi
        done <<< "$logLine"

        inf '[iCloud] Wrote transaction %d to log: %s' "$transaction" "$log"


    elif [[ $logLine = *'CoreData: Ubiquity:  Got final value for relationship:'* ]]; then
        # relationship value object
        relationship=? value=?
        {
            read relationship
            relationship=${relationship##*relationship: }

            while read -r line; do
                [[ $line = 'Object: <'* ]] && break
                value+="$line "
            done

            [[ $value != '?' ]] && value=${value#?}
            value=${value% }
        } <<< "$logLine"

        inf '[iCloud] Relationship %s => %s' "$relationship" "$value"


    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaselineRollResponseOperation:'*'Encountered an error while trying to respond to the roll of baseline:'* ]]; then
        # rollOperation:(localPeerID storeName modelVersionHash ubiquityRootLocation) baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation errorDomain errorCode localStoreKV
        domain=? code=?
        while read -r line; do
            [[ $line = 'Error: Error Domain='* ]] && {
                IFS='=' read -r _ domain code <<< "$line"
                domain=${domain%% Code} code=${code%% UserInfo=*}
                break
            }
        done <<< "$logLine"

        wrn '[iCloud] Baseline roll failed: %s, %s' "$domain" "$code"


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Scheduling baseline recovery operation on behalf of:'* ]]; then
        # importer ubiquityRootLocation localPeerID rollOperation:(localPeerID storeName modelVersionHash ubiquityRootLocation)
        wrn '[iCloud] Scheduling baseline recovery.'


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*"Can't process log with score: "*') after log with score:'* ]]; then
        # importer ubiquityRootLocation localPeerID kv kv
        failScore=? causeScore=? reason=?
        while read -r line; do
            [[ $line = "Can't process log"* ]] && {
                failScore=${line##*process log with score: <*([^:]): } failScore="<${failScore%%)*})"
                causeScore=${line##*after log with score: <*([^:]): } causeScore="<${causeScore%%)*})"
                read reason
                break
            }
        done <<< "$logLine"

        wrn '[iCloud] Not processing KV %s after KV %s: %s' "$failScore" "$causeScore" "$reason"


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Skipping incompatible operation (<PFUbiquityKnowledgeVector:'* ]]; then
        # importer ubiquityRootLocation localPeerID kv importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        score=? log=? transaction=?
        while read -r line; do
            if [[ $line = 'logScore: '* ]]; then
                score="<${line##*: }"
            elif [[ $line = 'transactionLogLocation: '* ]]; then
                log=${line##*/}
            elif [[ $line = 'transactionNumber: '* ]]; then
                transaction=${line##* }
            fi
        done <<< "$logLine"

        wrn '[iCloud] Skipping KV %s, from log %s, transaction: %d' "$score" "$log" "$transaction"


    elif [[ $logLine = *'CoreData: Ubiquity:  Got notification that store is about to commit:'* ]]; then
        # notification store saveRequest transactionType transactionNumber
        transaction=?
        while read -r line; do
            if [[ $line = 'transactionNumber: '* ]]; then
                transaction=${line##* }
            fi
        done <<< "$logLine"

        inf '[iCloud] Store committing transaction: %d' "$transaction"


    elif [[ $logLine = *'CoreData: Ubiquity:  Changes applied for transaction log content, managed object context changes:'* ]]; then
        # objects
        inserted=() updated=() deleted=() object=
        while read -r line; do
            if [[ $line = 'inserted: {('* ]]; then
                mode=inserted
            elif [[ $line = 'updated: {('* ]]; then
                mode=updated
            elif [[ $line = 'deleted: {('* ]]; then
                mode=deleted
            elif [[ $line = '})'?(,) ]]; then
                object=${object% }
                eval "$(printf '%q+=(%q)' "$mode" "$object")"
            elif [[ $line =~ ^'<'.*/([^/]*/[^/]*)'> ; data: {' ]]; then
                object=${BASH_REMATCH[1]}": "
            else
                line=${line//'"0x'+([[:alnum:]])' <x-coredata://'+([^\/])'/'/'"<'}
                object+="$line "
            fi
        done <<< "$logLine"

        inf '[iCloud] Imported %d changes into store:' "$(( ${#inserted[@]} + ${#updated[@]} + ${#deleted[@]} ))"
        for object in "${inserted[@]}"; do
            logColor=$green inf "+ %s" "$object"
        done
        for object in "${updated[@]}"; do
            logColor=$blue inf "* %s" "$object"
        done
        for object in "${deleted[@]}"; do
            logColor=$red inf "- %s" "$object"
        done


    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Skipping log because it has already been imported into the local store:'* ]]; then
        # importer ubiquityRootLocation localPeerID importOperation localPeerID location
        log=?
        while read -r line; do
            if [[ $line = *'<PFUbiquityLocation: '* ]]; then
                log=${line##*/}
            fi
        done <<< "$logLine"

        inf '[iCloud] Already imported: %s' "$log"


    # Messages with no useful content.
    elif [[ $logLine = *'CoreData: Ubiquity:  Successfully loaded receipt: <PFUbiquityPeerReceipt:'* ]]; then
        # permanentLocation safeLocation currentLocation kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Initializing stack'* ]]; then
        # stack metadataEntry metadataStoreFileLocation psc store filePresenter
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Setting up metadataMOC for stack:'* ]]; then
        # stack localPeerID ubiquityRootURL metadataContainerURL
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Stack Changes:'* ]]; then
        # peers transactionEntry:(actingPeer globalIDStr knowledgeVectorString localIDStr storeMetadata transactionDate transactionLogFilename transactionNumber transactionTypeNum) storeMetadata:(modelVersionHashString peerStates primaryKeyRanges storeIdentifier storeOptionsBinaryPlistData storeType storeURLString transactionEntries:(x-coredata://PFUbiquityTransactionEntry) ubiquityName ubiquityRelativePath ubiquityRootURLString)
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  About to save stack updates, metadata moc changes:'* ]]; then
        # peerStates peers storeMetadata
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  About to save stack: <_PFUbiquityStack:'* ]]; then
        # stack localPeerID ubiquityRootURL metadataContainerURL
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Added transaction entries to cache' ]]; then
        # -
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Path: '*' is a ubiquity root url.'* ]]; then
        # path
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Truncated path: '*' is a ubiquity root url.'*'Matches:'* ]]; then
        # path*2
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Exporter considering response to save:'* ]]; then
        # exporter localPeerID ubiquityRootLocation tempMoveTimer lastTransactionDate store storeOptions
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Exporter:'*'Will respond.'* ]]; then
        # exporter localPeerID ubiquityRootLocation tempMoveTimer lastTransactionDate
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  '*'Got change notification for url:'* ]]; then
        # filePresenter ubiquityRootLocation localPeerID url(*cdt|metadata.nosync|[peer]|baseline.zip|[storeName]/*|Data/[storeUUID]/*)
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Coordinated read finished for ubiquity root url:'* ]]; then
        # url
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityPeerReceipt:'*': Successfully wrote to file.'* ]]; then
        # receipt permanentLocation safeLocation currentLocation kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Checking peer file upload:'* ]]; then
        # receipt permanentLocation safeLocation currentLocation kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Successfully initialized baseline: <PFUbiquityBaseline:'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Successfully created staging directory:'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation url
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Successfully copied store to staging directory:'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation store-in-staging
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Got more than one path component for subpath: '*' of baseline staging directory:'* ]]; then
        # subpath staging
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Successfully removed contents of staging area.'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Baseline exists in the cloud, will evaluate other criteria to see if a new one can be rolled.' ]]; then
        # -
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Asked if rolling the baseline is possible, but not enough transactions have occurred. Only '*' local transactions have occurred of the required 100.' ]]; then
        # transactions-since-roll
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Total bytes:'* ]]; then
        # bytes-of-logs
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Store bytes: '*' at URL:'* ]]; then
        # bytes-of-store url
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Not enough log bytes to roll:'* ]]; then
        # bytes-of-logs
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Beginning metadata recovery for store:'* ]]; then
        # store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Metadata recovery for store:'*'Creating new store metadata.'* ]]; then
        # medic store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityStoreMetadataMedic:'*'Moving on to recreating the peer ranges.'* ]]; then
        # medic store metadata:(x-coredata:///PFUbiquityStoreMetadata modelVersionHashString peerStates primaryKeyRanges storeIdentifier storeOptionsBinaryPlistData storeType storeURLString transactionEntries ubiquityName ubiquityRelativePath ubiquityRootURLString)
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityStoreMetadataMedic:'*'Finished creating new peer ranges, moving to knowledge vector, peer states, and transaction entries.'* ]]; then
        # medic store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityStoreMetadataMedic:'*'Fetched knowledge vector:'* ]]; then
        # medic store kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityStoreMetadataMedic:'*'Finished.'* ]]; then
        # medic store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquitySetupAssistant:'*'Successfully recovered metadata'* ]]; then
        # assistant
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Removing identifiers from'* ]]; then
        # store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquitySetupAssistant:'*'Successfully wrote peer receipt file:'* ]]; then
        # assistant peerReceipt permanentLocation safeLocation currentLocation kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquitySetupAssistant:'*'Local store knowledge vector matches metadata knowledge vector.'* ]]; then
        # assistant
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquitySetupAssistant:'*"Didn't get a switchboard entry back after trying to register store:"* ]]; then
        # assistant store psc
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Starting scan of location:'* ]]; then
        # location
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityImportScanOperation:'*'got subpaths of root location: ('* ]]; then
        # importOperation paths
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityImportScanOperation:'*'Ignoring subpath (model version hash):'* ]]; then
        # importOperation path
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityImportScanOperation:'*'Got candidate log locations: ('* ]]; then
        # ?
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Initiated download for urls: ('* ]]; then
        # ?
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Finished scan of root location'* ]]; then
        # ? location(finished, pending, peers)
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Post store setup succeded.'* ]]; then
        # store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Ignoring private file:'* ]]; then
        # path
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Scheduling response to baseline:'* ]]; then
        # location
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Registered coordinators: {('* ]]; then
        # pscs
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  store name: '* ]]; then
        # storeName storeOptions store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Store:'* ]]; then
        # store
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Adding operation' ]]; then
        # -
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Responding to baseline:'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Checking to see if it can replace store with knowledge vector:'* ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Local store is current with the baseline' ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <PFUbiquityBaseline:'*'Finished check: 0' ]]; then
        # baseline permanentLocation safeLocation currentLocation storeName modelVersionHash baselineArchiveLocation
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Can adopt: 0 replace: 0'*'kv:'* ]]; then
        # kv
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Scheduling root scan'* ]]; then
        # importer ubiquityRootLocation localPeerID scan(x,y)
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'adding root scan: <PFUbiquityImportScanOperation: '*'> to queue:'* ]]; then
        # importer ubiquityRootLocation localPeerID scanOperation operationQueue
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Registering for application resumed notification.'* ]]; then
        # importer ubiquityRootLocation localPeerID
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Got empty knowledge vector from string:' ]]; then
        # -
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'importing operations:'* ]]; then
        # importer ubiquityRootLocation localPeerID importOperations
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Finished scheduling logs with context:'* ]]; then
        # importer ubiquityRootLocation localPeerID importContext pendingLogs scheduledLogs failedLogs ignoredlogs encounteredErrors
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Will reschedule pending logs:'* ]]; then
        # importer ubiquityRootLocation localPeerID pendingLogs failedLogs
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'will process operation:'* ]]; then
        # importer ubiquityRootLocation localPeerID importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Got set of persistent store coordinators for store named:'* ]]; then
        # importer ubiquityRootLocation localPeerID importOperation localPeerID storeName pscs
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordsImporter:'*'Wrote pending entries to disk after imports finished.' ]]; then
        # importer ubiquityRootLocation localPeerID importOperation localPeerID
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'Beginning parse of log file:'* ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber PFUbiquityTransactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'Cache KV matches initial KV'* ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'Successfully prefetched managed objects.' ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'successfully applied changes for object with global id:'* ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber globalId object:remotePeer
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'Successfully wrote changes.'* ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  <_PFUbiquityRecordImportOperation:'*'Successfully wrote metadata changes.'* ]]; then
        # importOperation localPeerID logScore transactionLog transactionLogLocation transactionNumber
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  About to apply changes from log contents.' ]]; then
        # -
        continue
    elif [[ $logLine = *'CoreData: Ubiquity:  Posting import notification:'* ]]; then
        # notification objects psc
        continue


    elif (( unhandled )); then
        firstLogLine=${logLine%%$'\n'*} firstLogLine=${firstLogLine#*] }
        [[ ${logLine#*$firstLogLine} ]] && firstLogLine+=" [...]"
        wrn -- '[unhandled] %s' "$firstLogLine"
        #wrn -- "$logLine"
    fi

done
